<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.3.5 - src/lfunc.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lfunc.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.3.5</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">84</td>
            <td class="headerCovTableEntry">84</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:17</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lfunc.c,v 2.45.1.1 2017/04/19 17:39:34 roberto Exp $
<span class="lineNum">       3 </span>            : ** Auxiliary functions to manipulate prototypes and closures
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define lfunc_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;stddef.h&gt;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;lfunc.h&quot;
<span class="lineNum">      18 </span>            : #include &quot;lgc.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lmem.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      22 </span>            : 
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span><span class="lineCov">        454 : CClosure *luaF_newCclosure (lua_State *L, int n) {</span>
<span class="lineNum">      26 </span><span class="lineCov">        454 :   GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));</span>
<span class="lineNum">      27 </span><span class="lineCov">        454 :   CClosure *c = gco2ccl(o);</span>
<span class="lineNum">      28 </span><span class="lineCov">        454 :   c-&gt;nupvalues = cast_byte(n);</span>
<span class="lineNum">      29 </span><span class="lineCov">        454 :   return c;</span>
<span class="lineNum">      30 </span>            : }
<span class="lineNum">      31 </span>            : 
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span><span class="lineCov">       2896 : LClosure *luaF_newLclosure (lua_State *L, int n) {</span>
<span class="lineNum">      34 </span><span class="lineCov">       2896 :   GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));</span>
<span class="lineNum">      35 </span><span class="lineCov">       2896 :   LClosure *c = gco2lcl(o);</span>
<span class="lineNum">      36 </span><span class="lineCov">       2896 :   c-&gt;p = NULL;</span>
<span class="lineNum">      37 </span><span class="lineCov">       2896 :   c-&gt;nupvalues = cast_byte(n);</span>
<span class="lineNum">      38 </span><span class="lineCov">      11342 :   while (n--) c-&gt;upvals[n] = NULL;</span>
<span class="lineNum">      39 </span><span class="lineCov">       2896 :   return c;</span>
<span class="lineNum">      40 </span>            : }
<span class="lineNum">      41 </span>            : 
<span class="lineNum">      42 </span>            : /*
<span class="lineNum">      43 </span>            : ** fill a closure with new closed upvalues
<span class="lineNum">      44 </span>            : */
<span class="lineNum">      45 </span><span class="lineCov">        472 : void luaF_initupvals (lua_State *L, LClosure *cl) {</span>
<span class="lineNum">      46 </span>            :   int i;
<span class="lineNum">      47 </span><span class="lineCov">        944 :   for (i = 0; i &lt; cl-&gt;nupvalues; i++) {</span>
<span class="lineNum">      48 </span><span class="lineCov">        472 :     UpVal *uv = luaM_new(L, UpVal);</span>
<span class="lineNum">      49 </span><span class="lineCov">        472 :     uv-&gt;refcount = 1;</span>
<span class="lineNum">      50 </span><span class="lineCov">        472 :     uv-&gt;v = &amp;uv-&gt;u.value;  /* make it closed */</span>
<span class="lineNum">      51 </span><span class="lineCov">        472 :     setnilvalue(uv-&gt;v);</span>
<span class="lineNum">      52 </span><span class="lineCov">        472 :     cl-&gt;upvals[i] = uv;</span>
<span class="lineNum">      53 </span>            :   }
<span class="lineNum">      54 </span><span class="lineCov">        472 : }</span>
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span>            : 
<span class="lineNum">      57 </span><span class="lineCov">       6339 : UpVal *luaF_findupval (lua_State *L, StkId level) {</span>
<span class="lineNum">      58 </span><span class="lineCov">       6339 :   UpVal **pp = &amp;L-&gt;openupval;</span>
<span class="lineNum">      59 </span>            :   UpVal *p;
<span class="lineNum">      60 </span>            :   UpVal *uv;
<span class="lineNum">      61 </span>            :   lua_assert(isintwups(L) || L-&gt;openupval == NULL);
<span class="lineNum">      62 </span><span class="lineCov">      14006 :   while (*pp != NULL &amp;&amp; (p = *pp)-&gt;v &gt;= level) {</span>
<span class="lineNum">      63 </span>            :     lua_assert(upisopen(p));
<span class="lineNum">      64 </span><span class="lineCov">       8758 :     if (p-&gt;v == level)  /* found a corresponding upvalue? */</span>
<span class="lineNum">      65 </span><span class="lineCov">       1091 :       return p;  /* return it */</span>
<span class="lineNum">      66 </span><span class="lineCov">       7667 :     pp = &amp;p-&gt;u.open.next;</span>
<span class="lineNum">      67 </span>            :   }
<span class="lineNum">      68 </span>            :   /* not found: create a new upvalue */
<span class="lineNum">      69 </span><span class="lineCov">       5248 :   uv = luaM_new(L, UpVal);</span>
<span class="lineNum">      70 </span><span class="lineCov">       5248 :   uv-&gt;refcount = 0;</span>
<span class="lineNum">      71 </span><span class="lineCov">       5248 :   uv-&gt;u.open.next = *pp;  /* link it to list of open upvalues */</span>
<span class="lineNum">      72 </span><span class="lineCov">       5248 :   uv-&gt;u.open.touched = 1;</span>
<span class="lineNum">      73 </span><span class="lineCov">       5248 :   *pp = uv;</span>
<span class="lineNum">      74 </span><span class="lineCov">       5248 :   uv-&gt;v = level;  /* current value lives in the stack */</span>
<span class="lineNum">      75 </span><span class="lineCov">       5248 :   if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */</span>
<span class="lineNum">      76 </span><span class="lineCov">         58 :     L-&gt;twups = G(L)-&gt;twups;  /* link it to the list */</span>
<span class="lineNum">      77 </span><span class="lineCov">         58 :     G(L)-&gt;twups = L;</span>
<span class="lineNum">      78 </span>            :   }
<span class="lineNum">      79 </span><span class="lineCov">       5248 :   return uv;</span>
<span class="lineNum">      80 </span>            : }
<span class="lineNum">      81 </span>            : 
<span class="lineNum">      82 </span>            : 
<span class="lineNum">      83 </span><span class="lineCov">       1716 : void luaF_close (lua_State *L, StkId level) {</span>
<span class="lineNum">      84 </span>            :   UpVal *uv;
<span class="lineNum">      85 </span><span class="lineCov">       6964 :   while (L-&gt;openupval != NULL &amp;&amp; (uv = L-&gt;openupval)-&gt;v &gt;= level) {</span>
<span class="lineNum">      86 </span>            :     lua_assert(upisopen(uv));
<span class="lineNum">      87 </span><span class="lineCov">       5248 :     L-&gt;openupval = uv-&gt;u.open.next;  /* remove from 'open' list */</span>
<span class="lineNum">      88 </span><span class="lineCov">       5248 :     if (uv-&gt;refcount == 0)  /* no references? */</span>
<span class="lineNum">      89 </span><span class="lineCov">         14 :       luaM_free(L, uv);  /* free upvalue */</span>
<span class="lineNum">      90 </span>            :     else {
<span class="lineNum">      91 </span><span class="lineCov">       5234 :       setobj(L, &amp;uv-&gt;u.value, uv-&gt;v);  /* move value to upvalue slot */</span>
<span class="lineNum">      92 </span><span class="lineCov">       5234 :       uv-&gt;v = &amp;uv-&gt;u.value;  /* now current value lives here */</span>
<span class="lineNum">      93 </span><span class="lineCov">       5234 :       luaC_upvalbarrier(L, uv);</span>
<span class="lineNum">      94 </span>            :     }
<span class="lineNum">      95 </span>            :   }
<span class="lineNum">      96 </span><span class="lineCov">       1716 : }</span>
<span class="lineNum">      97 </span>            : 
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span><span class="lineCov">       2077 : Proto *luaF_newproto (lua_State *L) {</span>
<span class="lineNum">     100 </span><span class="lineCov">       2077 :   GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));</span>
<span class="lineNum">     101 </span><span class="lineCov">       2077 :   Proto *f = gco2p(o);</span>
<span class="lineNum">     102 </span><span class="lineCov">       2077 :   f-&gt;k = NULL;</span>
<span class="lineNum">     103 </span><span class="lineCov">       2077 :   f-&gt;sizek = 0;</span>
<span class="lineNum">     104 </span><span class="lineCov">       2077 :   f-&gt;p = NULL;</span>
<span class="lineNum">     105 </span><span class="lineCov">       2077 :   f-&gt;sizep = 0;</span>
<span class="lineNum">     106 </span><span class="lineCov">       2077 :   f-&gt;code = NULL;</span>
<span class="lineNum">     107 </span><span class="lineCov">       2077 :   f-&gt;cache = NULL;</span>
<span class="lineNum">     108 </span><span class="lineCov">       2077 :   f-&gt;sizecode = 0;</span>
<span class="lineNum">     109 </span><span class="lineCov">       2077 :   f-&gt;lineinfo = NULL;</span>
<span class="lineNum">     110 </span><span class="lineCov">       2077 :   f-&gt;sizelineinfo = 0;</span>
<span class="lineNum">     111 </span><span class="lineCov">       2077 :   f-&gt;upvalues = NULL;</span>
<span class="lineNum">     112 </span><span class="lineCov">       2077 :   f-&gt;sizeupvalues = 0;</span>
<span class="lineNum">     113 </span><span class="lineCov">       2077 :   f-&gt;numparams = 0;</span>
<span class="lineNum">     114 </span><span class="lineCov">       2077 :   f-&gt;is_vararg = 0;</span>
<span class="lineNum">     115 </span><span class="lineCov">       2077 :   f-&gt;maxstacksize = 0;</span>
<span class="lineNum">     116 </span><span class="lineCov">       2077 :   f-&gt;locvars = NULL;</span>
<span class="lineNum">     117 </span><span class="lineCov">       2077 :   f-&gt;sizelocvars = 0;</span>
<span class="lineNum">     118 </span><span class="lineCov">       2077 :   f-&gt;linedefined = 0;</span>
<span class="lineNum">     119 </span><span class="lineCov">       2077 :   f-&gt;lastlinedefined = 0;</span>
<span class="lineNum">     120 </span><span class="lineCov">       2077 :   f-&gt;source = NULL;</span>
<span class="lineNum">     121 </span><span class="lineCov">       2077 :   return f;</span>
<span class="lineNum">     122 </span>            : }
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span><span class="lineCov">       1975 : void luaF_freeproto (lua_State *L, Proto *f) {</span>
<span class="lineNum">     126 </span><span class="lineCov">       1975 :   luaM_freearray(L, f-&gt;code, f-&gt;sizecode);</span>
<span class="lineNum">     127 </span><span class="lineCov">       1975 :   luaM_freearray(L, f-&gt;p, f-&gt;sizep);</span>
<span class="lineNum">     128 </span><span class="lineCov">       1975 :   luaM_freearray(L, f-&gt;k, f-&gt;sizek);</span>
<span class="lineNum">     129 </span><span class="lineCov">       1975 :   luaM_freearray(L, f-&gt;lineinfo, f-&gt;sizelineinfo);</span>
<span class="lineNum">     130 </span><span class="lineCov">       1975 :   luaM_freearray(L, f-&gt;locvars, f-&gt;sizelocvars);</span>
<span class="lineNum">     131 </span><span class="lineCov">       1975 :   luaM_freearray(L, f-&gt;upvalues, f-&gt;sizeupvalues);</span>
<span class="lineNum">     132 </span><span class="lineCov">       1975 :   luaM_free(L, f);</span>
<span class="lineNum">     133 </span><span class="lineCov">       1975 : }</span>
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span>            : 
<span class="lineNum">     136 </span>            : /*
<span class="lineNum">     137 </span>            : ** Look for n-th local variable at line 'line' in function 'func'.
<span class="lineNum">     138 </span>            : ** Returns NULL if not found.
<span class="lineNum">     139 </span>            : */
<span class="lineNum">     140 </span><span class="lineCov">        217 : const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {</span>
<span class="lineNum">     141 </span>            :   int i;
<span class="lineNum">     142 </span><span class="lineCov">        254 :   for (i = 0; i&lt;f-&gt;sizelocvars &amp;&amp; f-&gt;locvars[i].startpc &lt;= pc; i++) {</span>
<span class="lineNum">     143 </span><span class="lineCov">         48 :     if (pc &lt; f-&gt;locvars[i].endpc) {  /* is variable active? */</span>
<span class="lineNum">     144 </span><span class="lineCov">         33 :       local_number--;</span>
<span class="lineNum">     145 </span><span class="lineCov">         33 :       if (local_number == 0)</span>
<span class="lineNum">     146 </span><span class="lineCov">         11 :         return getstr(f-&gt;locvars[i].varname);</span>
<span class="lineNum">     147 </span>            :     }
<span class="lineNum">     148 </span>            :   }
<span class="lineNum">     149 </span><span class="lineCov">        206 :   return NULL;  /* not found */</span>
<span class="lineNum">     150 </span>            : }
<span class="lineNum">     151 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
